package com.fudan.backend.dao;

import com.fudan.backend.handler.IdTypeHandler;
import com.fudan.backend.handler.ListTypeHandler;
import com.fudan.backend.pojo.ReturnGoodsRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReturnGoodsRequestDao {
    @Results(id = "returnGoodsRequestMap", value = {
            @Result(column = "return_goods_request_id", property = "returnGoodsRequestId", typeHandler = IdTypeHandler.class),
            @Result(column = "initiate_time", property = "initiateTime"),
            @Result(column = "process_time", property = "processTime"),
            @Result(column = "store_id", property = "storeId", typeHandler = IdTypeHandler.class),
            @Result(column = "order_id", property = "orderId", typeHandler = IdTypeHandler.class),
            @Result(column = "user_id", property = "userId", typeHandler = IdTypeHandler.class),
            @Result(column = "status", property = "status"),
            @Result(column = "info", property = "info"),
            @Result(column = "return_reason", property = "returnReason")
    })
    @Select("select * from t_return_goods_request where user_id = #{userId}")
    List<ReturnGoodsRequest> selectReturnGoodsRequestByUserId(String userId);

    @ResultMap("returnGoodsRequestMap")
    @Select("select * from t_return_goods_request where store_id = #{storeId}")
    List<ReturnGoodsRequest> selectReturnGoodsRequestByStoreId(String storeId);

    @ResultMap("returnGoodsRequestMap")
    @Select("select * from t_return_goods_request where order_id = #{orderId} and status = 0")
    List<ReturnGoodsRequest> selectUnprocessedReturnGoodsRequestByOrderId(String orderId);

    @Insert("insert into t_return_goods_request values " +
            "(#{returnGoodsRequestId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, " +
            "#{initiateTime}, #{processTime}, " +
            "#{storeId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, " +
            "#{orderId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, " +
            "#{userId, typeHandler=com.fudan.backend.handler.IdTypeHandler}, " +
            "#{status}, #{info}, #{returnReason})")
    int insertReturnGoodsRequest(ReturnGoodsRequest returnGoodsRequest);

    @Update("update t_return_goods_request set " +
            "status = #{status}, info = #{info}, process_time = #{processTime} " +
            "where return_goods_request_id = #{returnGoodsRequestId}")
    int updateReturnGoodsRequest(ReturnGoodsRequest returnGoodsRequest);
}
